package cn.secby.goods.domain.vo;
import cn.secby.goods.domain.Sku;
import cn.secby.goods.domain.Spu;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Treeselect树结构实体类
 * 
 * @author hushuo
 */
@Data
public class TreeSelect implements Serializable
{
    private static final long serialVersionUID = 1L;

    /** 节点ID */
    private Long id;

    /** 节点名称 */
    private String label;

    /** 子节点 */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeSelect> children;

    public TreeSelect()
    {
    }


    public TreeSelect(Spu spu)
    {
        this.id = spu.getId();
        this.label = spu.getTitle();
        this.children = spu.getSkuList().stream().map(sku -> new TreeSelect(spu,sku)).collect(Collectors.toList());
    }

    public TreeSelect(Spu spu,Sku sku)
    {
        this.id = sku.getId();
        this.label =spu.getTitle()+"-"+sku.getSkuCode()+"("+sku.getStock()+")";
    }
}
